package android07.newtop.holder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import android07.newtop.R;
import android07.newtop.model.bean.NewsBean;
import android07.newtop.utils.GlideUtil;


/**
 * 新闻条目的holder
 * 所欲条目的信息都要在这里设置，无需另外传递数据进来，直接设置即可
 * 在NewTopViewHolder构造方法中findview  一定要用itemView.findViewById 否则会出现空指针异常
 *
 */
public class NewTopViewHolder extends BaseViewHolder<NewsBean.ResultBean.DataBean> {


    private android.widget.ImageView svusericon;
    private android.widget.TextView tvarticename;
    private android.widget.TextView tvarticeputtime;
    private android.widget.TextView tvarttitle;
    private android.widget.TextView tvarticetype;
    private android.widget.LinearLayout llrootline;
    private android.widget.ImageView svartlogo,iv_news_readed;
    private android.widget.RelativeLayout rlroot;

    public NewTopViewHolder(ViewGroup parent) {
        super(parent, R.layout.itemview_recommend_artice);

        //此行代码是为了 一键findviewby而书写  非常爽！！！！
//        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.itemview_recommend_artice, null);
        this.rlroot = (RelativeLayout) itemView.findViewById(R.id.rl_root);
        this.svartlogo = (ImageView) itemView.findViewById(R.id.sv_art_logo);
        this.llrootline = (LinearLayout) itemView.findViewById(R.id.ll_root_line);
        this.tvarticetype = (TextView) itemView.findViewById(R.id.tv_artice_type);
        this.tvarttitle = (TextView) itemView.findViewById(R.id.tv_art_title);
        this.tvarticeputtime = (TextView) itemView.findViewById(R.id.tv_artice_puttime);
        this.tvarticename = (TextView) itemView.findViewById(R.id.tv_artice_name);
        this.svusericon = (ImageView) itemView.findViewById(R.id.sv_usericon);
        this.iv_news_readed = (ImageView) itemView.findViewById(R.id.iv_news_readed);
    }


    /**
     * 这里是数据设置的方法，非常简单，面向对象编程
     *
     * 当数据成功获取，并且填充到Adpter这里可以设置每个item的数据
     * @param data
     */
    @Override
    public void setData(NewsBean.ResultBean.DataBean data) {
        super.setData(data);

        tvarttitle.setText(data.getTitle());
        tvarticeputtime.setText(data.getDate());
        tvarticetype.setText(data.getRealtype());
        GlideUtil.setCircleImageUrl(data.getThumbnail_pic_s(), svartlogo);
        GlideUtil.setCircleImageUrl(data.getThumbnail_pic_s03(), svusericon,8);
        tvarticename.setText(data.getAuthor_name());
        iv_news_readed.setVisibility(data.isreaded()?View.VISIBLE:View.INVISIBLE);

    }
}
